build: Add various compiler warnings and errors
authorEmmanuele Bassi <ebassi@gnome.org>
Sat, 15 Oct 2016 20:39:31 +0000 (21:39 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 17 Oct 2016 10:44:11 +0000 (11:44 +0100)
Just like GLib, GTK+ would benefit from getting warnings and errors from
the compilers.

We check various, common warnings, especially for a future use of C99;
additionally, we promote some warnings to errors, in order to ensure
that simple mistakes are caught during the development phase, before
they are submitted to the code repository.

configure.ac
gdk/Makefile.am
gtk/Makefile.am

index 35038a3a825c6cb4038456a325d5ed9a9adca8c5..3ce9c316df434c8547ec45c6174eaae053a8ff45 100644 (file)
@@ -1862,6 +1862,37 @@ _______EOF
 gdk_windowing='$GDK_WINDOWING'
 ])
 
+dnl Compiler flags; macro originates from systemd
+dnl See https://bugzilla.gnome.org/show_bug.cgi?id=608953
+AC_ARG_ENABLE(compile-warnings,
+              [AS_HELP_STRING([--disable-compile-warnings], [Do not use builtin compiler warnings])],
+              [],
+              [enable_compile_warnings=yes])
+AS_IF([test "x$enable_compile_warnings" = xyes], [
+  AX_APPEND_COMPILE_FLAGS([ dnl
+    -Wall dnl
+    -Wundef dnl
+    -Wnested-externs dnl
+    -Wpointer-arith dnl
+    -Wstrict-prototypes dnl
+    -Wcast-align dnl
+    -Wuninitialized dnl
+    -Wmissing-include-dirs dnl
+    -Wshadow dnl
+    -Wformat=2 dnl
+    -Wformat-non-literal dnl
+    -Wformat-security dnl
+    -Wimplicit-function-declaration dnl
+    -Werror=redundant-decls dnl
+    -Werror=write-strings dnl
+    -Werror=missing-declarations dnl
+    -Werror=missing-prototypes dnl
+    -Werror=empty-body dnl
+    -Werror=init-self dnl
+  ], [GTK_WARN_CFLAGS])
+])
+AC_SUBST(GTK_WARN_CFLAGS)
+
 dnl
 dnl Check for -Bsymbolic-functions linker flag used to avoid
 dnl intra-library PLT jumps, if available.
index e1b6d813861bba0dcb390c2bca3ef98a58f82e67..77b73195eb4fbe636b6207b482c4a70381fa706f 100644 (file)
@@ -207,7 +207,7 @@ common_sources =            \
        gdkresources.c
 
 libgdk_4_la_SOURCES = $(common_sources)
-libgdk_4_la_CFLAGS = $(AM_CFLAGS) $(GDK_HIDDEN_VISIBILITY_CFLAGS)
+libgdk_4_la_CFLAGS = $(AM_CFLAGS) $(GTK_WARN_CFLAGS) $(GDK_HIDDEN_VISIBILITY_CFLAGS)
 libgdk_4_la_LIBADD = $(GDK_DEP_LIBS) $(SHM_LIBS)
 libgdk_4_la_LDFLAGS = $(LDADD)
 
index 71b0b7583f1aa78e0a40d56b466b19011572de63..3b3ace51258cc0bbdfb5ec3d6bb9cc0e917b0960 100644 (file)
@@ -29,6 +29,7 @@ AM_CPPFLAGS =                                         \
        -I$(top_srcdir)/gdk                             \
        $(GMODULE_CFLAGS)                               \
        $(GTK_DEBUG_FLAGS)                              \
+       $(GTK_WARN_CFLAGS)                              \
        $(GDK_HIDDEN_VISIBILITY_CFLAGS)                 \
        $(GTK_DEP_CFLAGS)                               \
        $(INCLUDED_IMMODULE_DEFINE)